package com.mapfinal.server.auth;

import javax.servlet.http.HttpSession;

import com.lambkit.Lambkit;

public class AuthKit {
	
	public static final int AccountLockerNum = 3;

	public static Integer getLoginError(HttpSession session) {
    	Object error = session.getAttribute("login_error");
    	if(error!=null) {
    		Integer ier = (Integer) error;
    		return ier;
    	} else {
    		return 0;
    	}
    }
	public static Integer addLoginError(HttpSession httpSession) {
    	Object error = httpSession.getAttribute("login_error");
    	if(error!=null) {
    		Integer ier = (Integer) error;
    		ier++;
    		httpSession.setAttribute("login_error", ier);
    		return ier;
    	} else {
    		httpSession.setAttribute("login_error", Integer.valueOf(1));
    		return 1;
    	}
    }
	
	public static Integer getLoginError(String username) {
    	Object error = Lambkit.getCache().get("login_error", username);
    	if(error!=null) {
    		Integer ier = (Integer) error;
    		return ier;
    	} else {
    		return 0;
    	}
    }
    public static Integer addLoginError(String username) {
    	Object error = Lambkit.getCache().get("login_error", username);
    	if(error!=null) {
    		Integer ier = (Integer) error;
    		ier++;
    		Lambkit.getCache().put("login_error", username, ier, 3*60);//1小时
    		return ier;
    	} else {
    		Lambkit.getCache().put("login_error", username, Integer.valueOf(1), 3*60);
    		return 1;
    	}
    }
}
